<!--  Ofri Keidar 302933981 group 05 -->

<%@page import="controller.CustomerController"%>
<%@page import="controller.CommonValues"%>
<%@page import="view.WebCommons"%>
<%@page import="model.database.DBException"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="../../style/myTemplate/style.css"
	type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Get customer's orders</title>
</head>
<body>

	<span class="customHeader2">Customer's orders</span>

	<%
		// extract customer number from session
		Integer customerNumber = (Integer) session.getAttribute(WebCommons.CUSTOMER_NUMBER);

		try {

			// extract controller from session
			CustomerController controller = (CustomerController) session.getAttribute(WebCommons.CONTROLLER);

			// try getting customer's orders
			List<Map<String, String>> ordersDetails = controller.getOrders(customerNumber);

			// check success
			if (ordersDetails == null) {

				// display error message
				%>
				<span class="notify"><br>Sorry, could not get orders- no customer with the number "<%=customerNumber%>"</span>
				<%
				
			} else {

				// display orders in a table
				%>
				<div id="page" style="width: auto;">
					<div class="post">
						<div id="sidebar" style="width: auto;">
							<table border="2">
								<%
									// column names
								%>
								<tr>
									<td><span class="customMenuOption">Order Number</span></td>
									<td><span class="customMenuOption">Date</span></td>
									<td><span class="customMenuOption">Ordering Customer Number</span></td>
									<td><span class="customMenuOption">Product Ordered</span></td>
									<td><span class="customMenuOption">Amount</span></td>
									<td><span class="customMenuOption">Total Sum</span></td>
								</tr>
								<%
								// display data
								int numOfOrders = ordersDetails.size();
								for (int i = 0; i < numOfOrders; i++) {
			
									// display details of current order
									Map<String, String> currOrderDetails = ordersDetails.get(i);
								%>
								<tr>
									<td style="text-align: center;"><span class="customFormValue"><%=currOrderDetails.get(CommonValues.NUMBER)%></span></td>
									<td><span class="customFormValue"><%=currOrderDetails.get(CommonValues.DATE)%></span></td>
									<td style="text-align: center;"><span class="customFormValue"><%=currOrderDetails
														.get(CommonValues.ORDERING_CUSTOMER_NUMBER)%></span></td>
									<td><span class="customFormValue"><%=currOrderDetails.get(CommonValues.NAME)%></span></td>
									<td style="text-align: center;"><span class="customFormValue"><%=currOrderDetails.get(CommonValues.AMOUNT)%></span></td>
									<td><span class="customFormValue"><%=currOrderDetails.get(CommonValues.TOTAL_SUM)%></span></td>
								</tr>
								<%
								}
							%>
							</table>
						</div>
					</div>
				</div>							
				<%
			}

		} catch (DBException e) {
			
			// move to error page
			response.sendRedirect("../../commonPages/ErrorPage.jsp");
		}

		// return to main menu			
		String menuPage = (String) session.getAttribute(WebCommons.MAIN_MANU);
	%>
	<div id="footer">
		<span class="myLink"><A HREF="<%="../../menus/" + menuPage%>">Back
				to Menu</A></span>
	</div>

</body>
</html>